package main

/*
extern int get_int_size();
extern int get_long_size();
*/
import "C"

import (
	"fmt"
	"os"
	"path/filepath"
	"text/template"
)

func main() {
	intSize := C.get_int_size()
	longSize := C.get_long_size()

	data := map[string]int{"int_go": int(intSize) * 8, "long_go": int(longSize) * 8}
	fmt.Printf("int=%d\nlong=%d\n", data["int_go"], data["long_go"])

	tGoSwg, err := template.ParseFiles(filepath.Join("tmpls", "go.swg.tpl"))
	ferr(err)
	tTypemaps, err := template.ParseFiles(filepath.Join("tmpls", "typemaps.i.tpl"))
	ferr(err)

	os.MkdirAll("out", os.ModePerm)

	fGoSwg, err := os.Create(filepath.Join("out", "go.swg"))
	ferr(err)

	fTypemaps, err := os.Create(filepath.Join("out", "typemaps.i"))
	ferr(err)

	tGoSwg.Execute(fGoSwg, data)

	tTypemaps.Execute(fTypemaps, data)
}

func ferr(err error) {
	if err != nil {
		panic(err)
	}
}
